package org.easymis.oa.modules.main.controller;

import java.util.Calendar;
import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.easymis.entitys.mybatis.dto.CrmBusinessDto;
import org.easymis.entitys.mybatis.dto.CrmCustomerDto;
import org.easymis.entitys.mybatis.dto.CrmLeadsDto;
import org.easymis.entitys.mybatis.dto.Member;
import org.easymis.oa.service.attend.AttendRecordMng;
import org.easymis.oa.service.crm.CrmBusinessMng;
import org.easymis.oa.service.crm.CrmCustomerMng;
import org.easymis.oa.service.crm.CrmLeadsMng;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/index/")
public class OaIndexAction {
	@Autowired
	private CrmLeadsMng leadsService;
	@Autowired
	private CrmBusinessMng businessService;
	@Autowired
	private CrmCustomerMng customerService;
	@Resource
	private AttendRecordMng recordMng;
	@RequestMapping(value = "main")
	public String forwardIndexJsp(HttpServletRequest request, HttpSession session) throws Exception {
		Member staff =(Member)session.getAttribute("userInfo");
		//成交合同数
		int dealContractCount=0;
		request.setAttribute("dealContractCount", dealContractCount);
		//合同总金额
		int contractMoney=0;
		request.setAttribute("contractMoney", contractMoney);
		//已回款金额
		int hasTheReceivable=0;
		request.setAttribute("hasTheReceivable", hasTheReceivable);
		//预测
		int predictContractMoney=0;
		//预测签单数,预计签单金额,计划回款金额
		request.setAttribute("contractMoney", "10");
		//线索数,客户数,商机数
		Date createStartDate= new Date();
		 Date createEndDate = new Date();
		int leadsCount=leadsService.getCount(new CrmLeadsDto(staff.getOrgId(),staff.getStaffId(),createStartDate, createEndDate) );
		int businessCount=businessService.getCount(new CrmBusinessDto(staff.getOrgId(),staff.getStaffId(),createStartDate, createEndDate) );
		int customerCount=customerService.getCount(new CrmCustomerDto(staff.getOrgId(),staff.getStaffId(),createStartDate, createEndDate) );
		request.setAttribute("leadsCount", leadsCount);		
		request.setAttribute("customerCount", customerCount);
		request.setAttribute("businessCount", businessCount);
		//写跟进次数,拜访签到次数
		int businessFollowCount=businessService.getCount(new CrmBusinessDto(staff.getOrgId(),staff.getStaffId(),createStartDate, createEndDate) );
		int visitCount=businessService.getCount(new CrmBusinessDto(staff.getOrgId(),staff.getStaffId(),createStartDate, createEndDate) );
		
		request.setAttribute("businessFollowCount", businessFollowCount);
		request.setAttribute("visitCount", visitCount);
		request.setAttribute("signInState", recordMng.findSignInState(staff.getOrgId(), staff.getStaffId(), new Date()));
		request.setAttribute("base", "http://demo.easymis.cn/oa");
		return "index/main";
	}
	public static void main(String[] args ) {
		Calendar cal = Calendar.getInstance();
		System.out.println("今天的日期: " + cal.getTime());

		int day_of_week = cal.get(Calendar.DAY_OF_WEEK) - 2;
		cal.add(Calendar.DATE, -day_of_week);
		System.out.println("本周第一天: " + cal.getTime());

		cal.add(Calendar.DATE, 6);
		System.out.println("本周末: " + cal.getTime());
		}
	//<a href="report_center/detail_customer_adds_table?date=other&amp;start_date=2018-02-05&amp;end_date=2018-02-11&amp;creator_id=&amp;dimension=creator_id" class="fg-blue">0</a>

}
